/*
* MIT License
*
* Copyright (c) 2017 wen.gu <454727014@qq.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "tiny_plugin.h"
#include "tiny_plugin_manager.h"
#include "general_error.h"
#include "test_component1.h"

#define LOG_TAG "PluginTest"
#include "vos_log.h"
/***************************************************************************
*
* macro define
*
***************************************************************************/

/***************************************************************************
*
* data structure define
*
***************************************************************************/


/***************************************************************************
*
* API define
*
***************************************************************************/

void plugin_test()
{
    GPHD *pm = tfPluginManagerCreate();

    if (pm)
    {
        const char* pluginList[] = 
        {
            "test_plugin1.dll"
        };

        GU32 plCount = sizeof(pluginList) / sizeof(pluginList[0]);

        GS32 ret = tfPluginManagerLoad(pm, pluginList, plCount, GTRUE);

        if (G_OK == ret)
        {
            test_comp_create_param_t tccp;
            tccp.baseParam.type = TEST_COMP_TYPE;
            tccp.age = 5;

            test_component1_t* tc = NULL;

            ret = tfPluginManagerFind(pm, (tiny_component_t**)&tc, (tiny_comp_create_param_t*)&tccp);

            if (G_OK == ret)
            {
                tc->sayHello(tc);

                tc->setAge(tc, 10);
                tc->sayHello(tc);

                TF_COMP_RELEASE(tc);
            }
            else
            {
                LOGE("create component failed(0x%08x)\n", ret);
            }
        }
        else
        {
            LOGE("load plugins failed(0x%08x)\n", ret);
        }


        tfPluginManagerDestroy(pm);
    }
    else
    {
        LOGE("create plugin manager failed\n");
    }
}